
/*
'===============================================================================
'  Generated From - BLL_Component_Partial_Core.vbgen
'  
'  This object is partial class component representing a table in a database. It
'  contains core data access methods. Other partial classes should be used for 
'  implementing custom business logic. This class can be regenerated many times.
'  
'  Do not write custom business logic in this class as it will be overwritten 
'  next time the class is generated.
'
'  Version: 1.0
'  Date:	30/01/06
'  Summary: SelectOne, SelectAll, SelectAllWForeignKey, Insert, Update, Delete,
'  			DeleteAllWForeignKey, class for sorting.
'===============================================================================
*/
using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    [DataObjectAttribute]
	public partial class vwUsersWDivisionWRoleComponent
    {
        
		/// <summary>
        /// Default constructor.
        /// </summary>
		public vwUsersWDivisionWRoleComponent()
        {

        }

	
		/// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
		[DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
		public List<vwUsersWDivisionWRole> SelectAll(string sortExpression)
        {
            List<vwUsersWDivisionWRole> listvwUsersWDivisionWRole = new List<vwUsersWDivisionWRole>();
            PlacementManager.DAL.vwUsersWDivisionWRole_DAL o = new PlacementManager.DAL.vwUsersWDivisionWRole_DAL();

            DataSet ds = o.SelectAll();

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listvwUsersWDivisionWRole.Add(new vwUsersWDivisionWRole((string)row["UserName"], (int)row["UserId"], (string)row["FirstName"], (string)row["LastName"], (string)row["IdNumber"], (bool)row["IsActive"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"], (string)row["RoleName"], (int)row["DivisionId"]));
            }
			
			if (sortExpression == string.Empty)
            {
                sortExpression = "DateCreated desc";
            }

            listvwUsersWDivisionWRole.Sort(new vwUsersWDivisionWRoleComparer(sortExpression));
            return listvwUsersWDivisionWRole;
        }
	}
	
	public class vwUsersWDivisionWRoleComparer : IComparer<vwUsersWDivisionWRole>
    {
        private string _sortColumn;
        private bool _reverse;

        public vwUsersWDivisionWRoleComparer(string sortExpression)
        {
            _reverse = sortExpression.ToLowerInvariant().EndsWith(" desc");
            if (_reverse)
            {
                _sortColumn = sortExpression.Substring(0, sortExpression.Length - 5);
            }
            else
            {
                _sortColumn = sortExpression;
            }
        }

        public int Compare(vwUsersWDivisionWRole a, vwUsersWDivisionWRole b)
        {
            int retVal = 0;
            switch (_sortColumn)
            {
				case "UserName":
					retVal = String.Compare(a.UserName.ToString(), b.UserName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UserId":
					retVal = String.Compare(a.UserId.ToString(), b.UserId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "FirstName":
					retVal = String.Compare(a.FirstName.ToString(), b.FirstName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "LastName":
					retVal = String.Compare(a.LastName.ToString(), b.LastName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IdNumber":
					retVal = String.Compare(a.IdNumber.ToString(), b.IdNumber.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "IsActive":
					retVal = String.Compare(a.IsActive.ToString(), b.IsActive.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateCreated":
					retVal = String.Compare(a.DateCreated.ToString(), b.DateCreated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "CreatedBy":
					retVal = String.Compare(a.CreatedBy.ToString(), b.CreatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DateUpdated":
					retVal = String.Compare(a.DateUpdated.ToString(), b.DateUpdated.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "UpdatedBy":
					retVal = String.Compare(a.UpdatedBy.ToString(), b.UpdatedBy.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "RoleName":
					retVal = String.Compare(a.RoleName.ToString(), b.RoleName.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;
				case "DivisionId":
					retVal = String.Compare(a.DivisionId.ToString(), b.DivisionId.ToString(), StringComparison.InvariantCultureIgnoreCase);
					break;

            }
            return (retVal * (_reverse ? -1 : 1));
        }
    }
}
	
